<template>
  <div class="Patient_master_index">
    <div class="pubBig Privilege">
      <div class="h0">
        <p class="lt"></p>
      </div>
      <div class="dDownMain">
        <div
          class="twoBox"
          :style="this.$route.query.Token ? 'top:50px;left:10px' : 'top: 100px'"
        >
          <!-- 上层查询卡片 -->
          <el-card class="box-card" style="height: 150px">
            <el-form
              label-position="right"
              label-width="120px"
              :model="formLabelAlign_search"
            >
              <el-form-item
                label="患者姓名："
                style="width: 25%; display: inline-block"
              >
                <el-input
                  v-model="formLabelAlign_search.name"
                  style="width: 50%"
                  size="mini"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="证件号码："
                style="width: 25%; display: inline-block"
                size="mini"
              >
                <el-input
                  v-model="formLabelAlign_search.region"
                  style="width: 50%"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="患者标识号："
                style="width: 25%; display: inline-block"
                size="mini"
              >
                <el-input
                  v-model="formLabelAlign_search.type"
                  style="width: 50%"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="开始时间："
                style="width: 25%; display: inline-block"
                v-if="condition_show"
                size="mini"
              >
                <el-date-picker
                  v-model="formLabelAlign_search.time1"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                label="结束时间："
                style="width: 25%; display: inline-block"
                v-if="condition_show"
                size="mini"
              >
                <el-date-picker
                  v-model="formLabelAlign_search.time2"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item
                label="文档类型："
                style="width: 25%; display: inline-block"
                v-if="false"
                size="mini"
              >
                <template>
                  <el-select
                    filterable
                    v-model="formLabelAlign_search.value"
                    filterable
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in options"
                      :key="item.flag"
                      :label="item.label"
                      :value="item.flag"
                    >
                    </el-option>
                  </el-select>
                </template>
              </el-form-item>
              <el-form-item style="width: 25%; display: inline-block">
                <el-button
                  size="mini"
                  type="primary"
                  @click="(page.page = 1), getTableData()"
                  >查询</el-button
                >
                <el-button size="mini" @click="formLabelAlign_search = {}"
                  >重置</el-button
                >
                <el-button
                  size="mini"
                  @click="more_condition(condition_show)"
                  >{{ condition_show ? "收起" : "更多..." }}</el-button
                >
              </el-form-item>
            </el-form>
          </el-card>
          <!-- 下层表格卡片 -->
          <el-card class="box-card" style="height: 670px; margin-top: 10px">
            <div>
              <el-row>
                <el-col :span="12">
                  <span style="font-size: 24px">患者列表</span>
                </el-col>
                <el-col :span="12">
                  <span
                    >患者总数：<span style="color: red">990172</span>人</span
                  >
                  <span style="margin-left: 50px"
                    >文档总数：<span style="color: red">990172</span>份</span
                  >
                  <span style="margin-left: 50px">隐私保护：</span>
                  <el-switch
                    v-model="Lookrs"
                    active-color="#13ce66"
                    inactive-color="#ff4949"
                    @change="Lokr"
                  >
                  </el-switch>
                </el-col>
              </el-row>
            </div>
            <!-- 表格 -->
            <div>
              <el-table
                ref="multipleTable"
                :data="tableData"
                tooltip-effect="dark"
                style="width: 100%"
                @selection-change="handleSelectionChange_patient"
                height="520"
                border
              >
                <el-table-column label="主索引号" prop="Code">
                </el-table-column>
                <el-table-column prop="Name" label="患者姓名">
                </el-table-column>
                <el-table-column label="证件号码" prop="IdCard" width="165">
                  <template slot-scope="scope">
                    <span v-if="Lookrs">{{
                      scope.row.IdCard | formatIDcard
                    }}</span>
                    <span v-if="!Lookrs">{{ scope.row.IdCard }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="联系电话" prop="Telphone" width="130">
                  <template slot-scope="scope">
                    <span v-if="Lookrs">{{
                      scope.row.Telphone | formatPhone
                    }}</span>
                    <span v-if="!Lookrs">{{ scope.row.Telphone }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="性别名称" prop="Gender">
                </el-table-column>
                <el-table-column label="出生日期" prop=""> </el-table-column>
                <el-table-column label="ABO血型" prop="ABOCode">
                </el-table-column>
                <el-table-column label="RH血型" prop="RHCode">
                </el-table-column>
                <el-table-column label="联系人"> </el-table-column>
                <el-table-column label="联系人电话"> </el-table-column>
                <el-table-column label="联系人证件号"> </el-table-column>
                <el-table-column
                  label="操作"
                  width="60px"
                  align="center"
                  fixed="right"
                >
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      icon="el-icon-s-promotion"
                      @click="openAdd(scope.row)"
                    ></el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="block" style="text-align: center; padding-top: 20px">
              <el-pagination
                layout="prev, pager, next"
                :total="page.total"
                :page-size="page.limit"
                @current-change="page_change"
              >
              </el-pagination>
            </div>
          </el-card>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      formLabelAlign_search: {
        name: "",
        region: "",
        type: "",
        time1: "",
        time2: "",
      },
      options: [
        {
          label: "病历概要",
          flag: "EMR01",
        },
        {
          label: "门(急)诊病历",
          flag: "EMR02",
        },
        {
          label: "急诊留观病历",
          flag: "EMR03",
        },
        {
          label: "西药处方",
          flag: "EMR04",
        },
        {
          label: "中药处方",
          flag: "EMR05",
        },
        {
          label: "检查报告",
          flag: "EMR06",
        },
        {
          label: "检验报告",
          flag: "EMR07",
        },
        {
          label: "治疗记录",
          flag: "EMR08",
        },
        {
          label: "一般手术记录",
          flag: "EMR09",
        },
        {
          label: "麻醉术前访视记录",
          flag: "EMR10",
        },
        {
          label: "麻醉记录",
          flag: "EMR11",
        },
        {
          label: "麻醉术后访视记录",
          flag: "EMR12",
        },
        {
          label: "输血记录",
          flag: "EMR13",
        },
        {
          label: "待产记录",
          flag: "EMR14",
        },
        {
          label: "阴道分娩记录",
          flag: "EMR15",
        },
        {
          label: "剖宫产记录",
          flag: "EMR16",
        },
        {
          label: "一般护理记录",
          flag: "EMR17",
        },
        {
          label: "病重（病危）护理记录",
          flag: "EMR18",
        },
        {
          label: "手术护理记录",
          flag: "EMR19",
        },
        {
          label: "生命体征测量记录",
          flag: "EMR20",
        },
        {
          label: "出入量记录",
          flag: "EMR21",
        },
        {
          label: "高值耗材使用记录",
          flag: "EMR22",
        },
        {
          label: "入院评估",
          flag: "EMR23",
        },
        {
          label: "护理计划",
          flag: "EMR24",
        },
        {
          label: "出院评估与指导",
          flag: "EMR25",
        },
        {
          label: "手术知情同意书",
          flag: "EMR26",
        },
        {
          label: "麻醉知情同意书",
          flag: "EMR27",
        },
        {
          label: "输血治疗同意书",
          flag: "EMR28",
        },
        {
          label: "特殊检查及特殊治疗同意书",
          flag: "EMR29",
        },
        {
          label: "病危（重）通知书",
          flag: "EMR30",
        },
        {
          label: "其他知情同意书",
          flag: "EMR31",
        },
        {
          label: "住院病案首页",
          flag: "EMR32",
        },
        {
          label: "中医住院病案首页",
          flag: "EMR33",
        },
        {
          label: "入院记录",
          flag: "EMR34",
        },
        {
          label: "24小时内入出院记录",
          flag: "EMR35",
        },
        {
          label: "24小时内入院死亡记录",
          flag: "EMR36",
        },
        {
          label: "住院病程记录 首次病程记录",
          flag: "EMR37",
        },
        {
          label: "住院病程记录 日常病程记录",
          flag: "EMR38",
        },
        {
          label: "住院病程记录-上级医师查房记录",
          flag: "EMR39",
        },
        {
          label: "住院病程记录-疑难病例讨论记录",
          flag: "EMR40",
        },
        {
          label: "住院病程记录-交接班记录",
          flag: "EMR41",
        },
        {
          label: "住院病程记录-转科记录",
          flag: "EMR42",
        },
        {
          label: "住院病程记录-阶段小结",
          flag: "EMR43",
        },
        {
          label: "住院病程记录-抢救记录",
          flag: "EMR44",
        },
        {
          label: "住院病程记录-会诊记录",
          flag: "EMR45",
        },
        {
          label: "住院病程记录-术前小结",
          flag: "EMR46",
        },
        {
          label: "住院病程记录-术前讨论",
          flag: "EMR47",
        },
        {
          label: "住院病程记录-术后首次病程记录",
          flag: "EMR48",
        },
        {
          label: "住院病程记录-出院记录",
          flag: "EMR49",
        },
        {
          label: "住院病程记录-死亡记录",
          flag: "EMR50",
        },
        {
          label: "住院病程记录-死亡病例讨论记录",
          flag: "EMR51",
        },
        {
          label: "住院医嘱",
          flag: "EMR52",
        },
        {
          label: "出院小结",
          flag: "EMR53",
        },
      ],
      switch_yinsi: true,
      tableData: [],
      multipleSelection: [],
      dialogVisible_Add: false,
      dialogVisible_search: false,
      formLabelAlign_items_search: {},
      formLabelAlign_items_Add: {},
      checked: true,
      tableData_item_Add: [
        {
          label: "病历概要",
          flag: "EMR01",
        },
        {
          label: "门(急)诊病历",
          flag: "EMR02",
        },
        {
          label: "急诊留观病历",
          flag: "EMR03",
        },
        {
          label: "西药处方",
          flag: "EMR04",
        },
        {
          label: "中药处方",
          flag: "EMR05",
        },
        {
          label: "检查报告",
          flag: "EMR06",
        },
        {
          label: "检验报告",
          flag: "EMR07",
        },
        {
          label: "治疗记录",
          flag: "EMR08",
        },
        {
          label: "一般手术记录",
          flag: "EMR09",
        },
        {
          label: "麻醉术前访视记录",
          flag: "EMR10",
        },
        {
          label: "麻醉记录",
          flag: "EMR11",
        },
        {
          label: "麻醉术后访视记录",
          flag: "EMR12",
        },
        {
          label: "输血记录",
          flag: "EMR13",
        },
        {
          label: "待产记录",
          flag: "EMR14",
        },
        {
          label: "阴道分娩记录",
          flag: "EMR15",
        },
        {
          label: "剖宫产记录",
          flag: "EMR16",
        },
        {
          label: "一般护理记录",
          flag: "EMR17",
        },
        {
          label: "病重（病危）护理记录",
          flag: "EMR18",
        },
        {
          label: "手术护理记录",
          flag: "EMR19",
        },
        {
          label: "生命体征测量记录",
          flag: "EMR20",
        },
        {
          label: "出入量记录",
          flag: "EMR21",
        },
        {
          label: "高值耗材使用记录",
          flag: "EMR22",
        },
        {
          label: "入院评估",
          flag: "EMR23",
        },
        {
          label: "护理计划",
          flag: "EMR24",
        },
        {
          label: "出院评估与指导",
          flag: "EMR25",
        },
        {
          label: "手术知情同意书",
          flag: "EMR26",
        },
        {
          label: "麻醉知情同意书",
          flag: "EMR27",
        },
        {
          label: "输血治疗同意书",
          flag: "EMR28",
        },
        {
          label: "特殊检查及特殊治疗同意书",
          flag: "EMR29",
        },
        {
          label: "病危（重）通知书",
          flag: "EMR30",
        },
        {
          label: "其他知情同意书",
          flag: "EMR31",
        },
        {
          label: "住院病案首页",
          flag: "EMR32",
        },
        {
          label: "中医住院病案首页",
          flag: "EMR33",
        },
        {
          label: "入院记录",
          flag: "EMR34",
        },
        {
          label: "24小时内入出院记录",
          flag: "EMR35",
        },
        {
          label: "24小时内入院死亡记录",
          flag: "EMR36",
        },
        {
          label: "住院病程记录 首次病程记录",
          flag: "EMR37",
        },
        {
          label: "住院病程记录 日常病程记录",
          flag: "EMR38",
        },
        {
          label: "住院病程记录-上级医师查房记录",
          flag: "EMR39",
        },
        {
          label: "住院病程记录-疑难病例讨论记录",
          flag: "EMR40",
        },
        {
          label: "住院病程记录-交接班记录",
          flag: "EMR41",
        },
        {
          label: "住院病程记录-转科记录",
          flag: "EMR42",
        },
        {
          label: "住院病程记录-阶段小结",
          flag: "EMR43",
        },
        {
          label: "住院病程记录-抢救记录",
          flag: "EMR44",
        },
        {
          label: "住院病程记录-会诊记录",
          flag: "EMR45",
        },
        {
          label: "住院病程记录-术前小结",
          flag: "EMR46",
        },
        {
          label: "住院病程记录-术前讨论",
          flag: "EMR47",
        },
        {
          label: "住院病程记录-术后首次病程记录",
          flag: "EMR48",
        },
        {
          label: "住院病程记录-出院记录",
          flag: "EMR49",
        },
        {
          label: "住院病程记录-死亡记录",
          flag: "EMR50",
        },
        {
          label: "住院病程记录-死亡病例讨论记录",
          flag: "EMR51",
        },
        {
          label: "住院医嘱",
          flag: "EMR52",
        },
        {
          label: "出院小结",
          flag: "EMR53",
        },
      ],
      condition_show: false,
      page: {
        page: 1,
        limit: 10,
        total: 1,
      },
      isTitle: "",
      isPatientCode: [], //患者主索引列表
      theAddType: 2, //确定按钮的类型 1 批量 2 单个
      isEMPI_list: [], // 文件类型列表
      PatientCode: "", //单个患者索引号
      Lookrs: true, //隐私保护开关
    };
  },
  methods: {
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange_patient(val) {
      //患者选中事件
      let arr = [];
      for (var i in val) {
        arr.push(val[i].Code);
      }
      console.log(arr);
      this.isPatientCode = arr;
      if (arr.length <= 0) {
        this.theAddType = 2;
      }
      if (arr.length > 0) {
        this.theAddType = 1;
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleClose_search() {
      this.dialogVisible_search = false;
      this.formLabelAlign_items_search = {};
    },
    openSearch(val) {
      console.log(val);
      this.formLabelAlign_items_search = val;
      this.dialogVisible_search = true;
    },
    handleClose_Add() {
      // 弹层关闭
      this.dialogVisible_Add = false;
      this.formLabelAlign_items_Add = {};
      this.isEMPI_list = [];
      this.$refs.multipleTable_EMPI.clearSelection();
    },
    Add_P_E() {
      // 弹层确定
      if (this.theAddType == 1) {
        // 批量
        let body = {
          version: this.formLabelAlign_items_Add.type1,
          startTime: this.formLabelAlign_items_Add.value1,
          endTime: this.formLabelAlign_items_Add.value2,
          codeData: this.isPatientCode,
          fileData: this.isEMPI_list,
        };
        this.$post("/DocumentManage/Main/BatchCDA", body).then((res) => {
          if (res.code == 0) {
            this.handleClose_Add();
            this.$refs.multipleTable.clearSelection();
            this.$message({
              message: "操作成功",
              type: "success",
            });
          }
        });
      }
      if (this.theAddType == 2) {
        // 单个
        let body = {
          version: this.formLabelAlign_items_Add.type1,
          startTime: this.formLabelAlign_items_Add.value1,
          endTime: this.formLabelAlign_items_Add.value2,
          codeData: this.PatientCode,
          fileData: this.isEMPI_list,
        };
        this.$post("/DocumentManage/Main/CreateCDA", body).then((res) => {
          if (res.code == 0) {
            this.handleClose_Add();
            this.$message({
              message: "操作成功",
              type: "success",
            });
          }
        });
      }
    },
    openAdd(val) {
      // 单个下载
      console.log(val);
      let index = val.Code;
      // window.open("#/CDR?id=" + index);
      this.$router.push("#/CDR?id=" + index);
    },
    handleSelectionChange_EMPI(val) {
      // 弹层EMPI选择
      let arr = [];
      for (var i in val) {
        arr.push(val[i].flag);
      }
      console.log(arr);
      this.isEMPI_list = arr;
    },
    openLook(val) {
      console.log(val);
      this.$message({
        message: "患者信息不完整无法调阅",
        type: "warning",
      });
    },
    more_condition(val) {
      // console.log(val);
      if (val) {
        this.condition_show = false;
        this.formLabelAlign_search.time1 = "";
        this.formLabelAlign_search.time2 = "";
        this.formLabelAlign_search.value = "";
      }
      if (!val) {
        this.condition_show = true;
      }
    },
    getTableData() {
      // 获取表格数据
      this.$post(
        "/DocumentManage/Main/PatientList?name=" +
          this.formLabelAlign_search.name +
          "&idCard=" +
          this.formLabelAlign_search.region +
          "&code=" +
          this.formLabelAlign_search.type +
          "&startTime=" +
          this.formLabelAlign_search.time1 +
          "&endTime=" +
          this.formLabelAlign_search.time2 +
          "&page=" +
          this.page.page +
          "&limit=" +
          this.page.limit
      ).then((res) => {
        if (res.code == 0) {
          console.log(res);
          this.page.total = res.data.TotalCount;
          this.tableData = res.data.list;
        }
      });
    },
    page_change(val) {
      this.page.page = val;
      this.getTableData();
    },
    addS() {
      // 批量生成
      this.dialogVisible_Add = true;
    },
    Lokr(val) {
      // 隐私保护切换事件
      this.Lookrs = val;
    },
  },
  mounted() {
    // document.getElementById("2").focus();
    this.getTableData();
  },
  created() {
    if (this.$route.query.Token) {
      localStorage.setItem("Token", this.$route.query.Token);
    }
  },
  filters: {
    formatIDcard(value) {
      // 身份证
      if (!value) return "";
      let str = value;
      str = str.toString().replace(/^(.{3})(?:\w+)(.{4})$/, "$1***********$2");
      return str;
    },
    formatPhone(value) {
      // 电话
      if (!value) return "";
      let str = value;
      str = str.toString().replace(/^(\d{3})(\d{4})(\d{4})/g, "$1****$3");
      return str;
    },
  },
};
</script>
<style lang="scss">
.Patient_master_index {
  .top-input {
    display: inline-block;
    width: 350px;
  }

  .box-top {
    margin-top: 15px;
    margin-left: 5px;
  }
}
</style>
